define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'clothmaking_product/index/index' + location.search,
                    add_url: 'clothmaking_product/index/add',
                    edit_url: 'clothmaking_product/index/edit',
                    del_url: 'clothmaking_product/index/del',
                    multi_url: 'clothmaking_product/index/multi',
                    import_url: 'clothmaking_product/index/import',
                    table: 'clothmaking_product',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'name', title: __('Name'), operate: 'LIKE' },
                        { field: 'alias', title: __('Alias'), operate: 'LIKE' },
                        { field: 'thickness', title: __('Thickness'), operate: 'BETWEEN' },
                        { field: 'width', title: __('Width'), operate: 'BETWEEN' },
                        { field: 'length', title: __('Length'), operate: 'BETWEEN' },
                        { field: 'color', title: __('Color'), operate: 'LIKE' },
                        { field: 'density', title: __('Density'), operate: 'BETWEEN' },
                        { field: 'weigh', title: __('Weigh'), operate: false },
                        { field: 'stock', title: __('stock') },
                        { field: 'Material', title: __('Material'), operate: 'LIKE' },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [{
                                //  text: "库存记录",
                                title: __('库存记录'),
                                classname: 'btn btn-xs btn-success btn-dialog',
                                icon: 'fa fa-list',
                                url: 'clothmaking/stock/index?pid={ids}'
                            }, ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});